<template>

    <view class="container">



        <view>
            <text style="font-size: 18px; font-weight: bold;display: block; margin: 20rpx">观众热评</text>
        </view>
        <!--  评价 -->
        <view class="evaluate">
            <view class="evaluateCenter">
                <view class="evaluateItem" v-for="(item, index) in CommentlItemList" :key="index">
                    <view class="evaluateTip dfsb">
                        <view class="img">
                            <image :src="item.iconUrl" mode="scaleToFill"></image>
                        </view>
                        <view class="right">
                            <view class="righttip">{{ item.name }}</view>
                            <view class="bottom dfsb">
                                <view class="star">
                                    <text>{{ item.star }}分</text>
                                    <uni-rate size='12' activeColor='#fd9130' :is-fill="false" readonly disabledColor=''
                                        allow-half :value="item.star || 3.5" />
                                </view>
                                <view class="time">{{ item.publishTime }}</view>
                            </view>
                        </view>
                    </view>
                    <view class="evaluateText" :class="{ lineclamp3: item.contentAll }"> {{ item.comment }} </view>
                    <view class="" v-if="item.isMore">
                        <view class="rightText" v-if="item.contentAll" @click="changeAllFun(item, index)">全部</view>
                        <view class="rightText" v-else @click="changeAllFun(item, index)">收起</view>
                    </view>


                    <!-- 预留图片列表 可显示评论列表 -->
                    <!-- <view class="evaluateListImg">
                        <view class="evaluateListImgItem " v-for="(itm, ind) in item.imageList" :key="ind">
                            <image :src="itm.url" mode="scaleToFill"></image>
                        </view>
                    </view> -->

                </view>
            </view>
        </view>

    </view>

</template>

<script setup lang="ts">
import type { Comment } from '@/types/comment';
import { getCommentByIdAPI } from '@/services/comment'
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app'


// 获取页面参数
const query = defineProps<{
    id: string
}>()


const CommentlItemList = ref<Comment[]>()


// 获取评论数据
const CommentlItemListData = async () => {
    const res = await getCommentByIdAPI(query.id, "1")
    CommentlItemList.value = res.result
}




// 页面加载
onLoad(async () => {
    await CommentlItemListData()


    setContentIsShow()
});



/** 为文本设置属性是否全部展开或收起 */
function setContentIsShow() {


    CommentlItemList.value!.forEach(item => {
        if (item.comment.length > 60) {
            item.isMore = true
            item.contentAll = true
        } else {
            item.isMore = false
            item.contentAll = false
        }
    })
};


function changeAllFun(item: Comment, index: number) {
    let list: Comment[] = JSON.parse(JSON.stringify(CommentlItemList.value));
    list.forEach((elem: Comment, ind: number) => {
        if (index === ind) {
            elem.contentAll = !elem.contentAll
        }
    })
    CommentlItemList.value = list
};

// list: [
//     {
//         name: '马保国',
//         image: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e01ec0ba02a9.jpg',
//         star: 4.5,
//         time: '2021.06.06',
//         content: '服务好，景色好，山河锦绣，树木茂盛，空气清新，鸟语花香，人杰地灵服务好，景色好，山河锦绣，树木茂盛，空气清新，鸟语花香，人杰地灵服务好，景色好，山河锦绣，树木茂盛，空气清新，鸟语花香，人杰地灵服务好，景色好，山河锦绣，树木茂盛，空气清新，鸟语花香，人杰地灵服务好，景色好，山河锦绣，树木茂盛，空气清新，鸟语花香，人杰地灵',
//         imageList: [
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//         ]
//     },
//     {
//         name: '留念&伤感1999',
//         image: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e01f3cb402aa.jpg',
//         star: 4.5,
//         time: '2021.06.06',
//         content: '服务好服务好服务好服务好，景色好，山河锦绣，树木茂盛树木茂盛树木茂盛树木茂盛树木茂盛树木茂盛树木茂盛树木茂盛树木茂盛树木茂盛树木茂盛树木茂盛，空气清新，鸟语花香，人杰地灵',
//         imageList: [
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//             { url: 'https://slzh-oss.oss-cn-beijing.aliyuncs.com/usercenter/template/2c94809a787cec070179e0234e7902ab.png' },
//         ]
//     },
// ]

//     methods: {
//         getlist() {
//             this.list.forEach(item => {
//                 if (item.content.length > 60) {
//                     item.isMore = true
//                     item.contentAll = true
//                 } else {
//                     item.isMore = false
//                     item.contentAll = false
//                 }
//             })
//         },
//         changeAllFun(item, index) {
//             let list = JSON.parse(JSON.stringify(this.list));
//             list.forEach((elem, ind) => {
//                 if (index === ind) {
//                     elem.contentAll = !elem.contentAll
//                 }
//             })
//             this.list = list
//         }
//     }

// }
</script>

<style lang="scss" scoped>
.container {

    margin-top: 70rox;
    font-size: 12px;
    display: inline-block;
    color: #1d1d1d;
    position: relative;

}

// 游客评价
.evaluate .evaluateCenter .evaluateItem {
    display: inline-block;
}

.rightText {
    color: #4399FC;
    text-align: right;
}

.evaluate {
    .tip {
        padding: 15px;

        .left {
            font-size: 14px;
            font-weight: 500;
            color: #0c1317;
        }

        .right {
            color: #0f9efa;
            font-weight: bold;

            image {
                margin-left: 6px;
                width: 16px;
                height: 16px;
            }
        }
    }

    .evaluateCenter {
        overflow-x: auto;

        .evaluateItem {
            width: 84%;
            background-color: #FFFFFF;
            padding: 15px;
            border-radius: 10px;
            margin: 10px 15px 0 15px;

            .evaluateTip {
                display: flex;

                .img {
                    width: 42px;
                    height: 42px;
                    display: table;

                    image {
                        width: 42px;
                        height: 42px;
                        border-radius: 50%;
                    }
                }

                .right {
                    width: 100%;
                    padding-left: 15px;

                    .righttip {
                        font-size: 13px;
                        font-family: PingFang SC;
                        font-weight: bold;
                        color: #0C1317;
                        padding-bottom: 5px;
                    }

                    .bottom {
                        .star {
                            display: flex;
                            color: #fd9130;

                            text {
                                padding-right: 4px;
                                font-size: 11px;
                                color: #0f9efa;
                                font-weight: bold;
                            }
                        }

                        .time {
                            color: #969899;
                        }
                    }
                }
            }

            .evaluateText {
                margin: 10px 0 0 0;
                letter-spacing: 0.5px;
                line-height: 20px;
            }

            .lineclamp3 {
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 3;
                -webkit-box-orient: vertical;
                white-space: normal;
            }

            .evaluateListImg {
                width: 100%;

                .evaluateListImgItem {
                    width: 66px;
                    height: 66px;
                    float: left;
                    margin-right: 6px;

                    image {
                        width: 66px;
                        height: 66px;
                        border-radius: 5px;
                    }
                }
            }


        }
    }
}
</style>
